<!--suppress ALL -->
<template>
  <dialog-editor ref="dialog"></dialog-editor>
</template>

<script>
import DialogEditor from '@/components/DialogEditor'
import dialogMixins from '@/utils/commonDialogMixins'

export default {
  mixins: [dialogMixins],
  components: {DialogEditor},
  data() {
    return {
      dataFormConfig: {
        contractOrderId:{
          label: '合同编号',
          type: 'list',
          list: [],
          filterable: true,
          placeholder: '请输入合同编号'
        },
        clientId: {
          label: '客户',
          type: 'list',
          list: [],
          filterable: true,
          placeholder: '请输入客户名'
        },
        productId: {
          label: '产品',
          type: 'list',
          list: [],
          filterable: true,
          placeholder: '请选择产品',
          isNeedAdd: true,
          addNewItemFunc: this.addNewProduct
        },
        modelNo: {
          label: '模具编号',
          placeholder: '请选择模具'
        },
        unitPrice: {
          label: '模具价格',
          type: 'number',
          max: 10000000
        },
        modelCategoryId: {
          label: '模具类型',
          type: 'list',
          placeholder: '请选择模具类型',
          list: []
        },
        modelType: {
          label: '生产/试样模',
          type: 'radio',
          radioBorder: false,
          radioList: [
            {text: '试样模', label: 0},
            {text: '生产模', label: 1}
          ],
          default: 1
        },
        successMo: {
          label: '成模数量',
          type: 'number',
          max: 1000
        },
        primaryMo: {
          label: '初模数量',
          type: 'number',
          max: 1000,
          default: 0
        },
        menTou: {
          label: '闷头数量',
          type: 'number',
          max: 1000,
          default: 0
        },
        louDou: {
          label: '漏斗数量',
          type: 'number',
          max: 1000,
          default: 0
        },
        kouZi: {
          label: '口子数量',
          type: 'number',
          max: 1000,
          default: 0
        },
        xinZi: {
          label: '芯子数量',
          type: 'number',
          max: 1000,
          default: 0
        },
        qiTou: {
          label: '气头数量',
          type: 'number',
          max: 1000,
          default: 0
        },
        jiaZi: {
          label: '夹子数量',
          type: 'number',
          max: 1000,
          default: 0
        },
        lengQue: {
          label: '冷却数量',
          type: 'number',
          max: 1000,
          default: 0
        },
        qianPian: {
          label: '钳片数量',
          type: 'number',
          max: 1000,
          default: 0
        },
        bottomMo: {
          label: '底模数量',
          type: 'number',
          max: 1000,
          default: 0
        },
        localProduct: {
          label: '在供应商做大货',
          type: 'switch',
          activeValue: 1,
          inactiveValue: 0,
          default: 1
        },
        dayTime: {
          label: '日期',
          type: 'date',
          placeholder: '请选择日期'
        },
        remark: {
          label: '备注',
          placeholder: '请输入备注'
        },
        status: {
          label: '状态',
          type: 'switch',
          activeValue: 1,
          inactiveValue: 0,
          default: 1
        }
      }
    }
  },
  methods: {
    successMoChangedHandle() {
      this.dataForm.successMo = this.dataForm.successMo || 0

      this.dataForm.primaryMo = this.dataForm.successMo
      this.dataForm.jiaZi = this.dataForm.successMo
      this.dataForm.kouZi = this.dataForm.successMo
      this.dataForm.lengQue = this.dataForm.successMo
      this.dataForm.louDou = this.dataForm.successMo
      this.dataForm.menTou = this.dataForm.successMo
      this.dataForm.qiTou = this.dataForm.successMo
      this.dataForm.xinZi = this.dataForm.successMo
      this.dataForm.qianPian = this.dataForm.successMo
      this.dataForm.bottomMo = this.dataForm.successMo
    },
    init(id,property) {
      this.dataForm.id = id || 0
     // this.initModelInfoList('modelId')
      this.initModelCategoryList()
      this.initProductInfoList()
      this.initClientInfoList()
      this.initContractOrderInfoList('contractOrderId')


      this.$refs.dialog.initDialog({
        dataForm: this.dataForm,
        config: this.dataFormConfig,
        dataRule: this.getNeedDataRule('contractOrderId','clientId', 'productId','modelNo','modelCategoryId' ,'localProduct', 'successMo', 'primaryMo', 'menTou', 'louDou', 'kouZi', 'xinZi', 'qiTou', 'jiaZi', 'lengQue', 'modelCategoryId', 'unitPrice','dayTime'),
        initApi: 'orderApi/orderModelInfo',
        saveApi: 'orderApi/saveOrderModel',
        updateApi: 'orderApi/updateOrderModel',
        objectName: 'orderModel'
      })
      this.$nextTick(() => {
        if (!this.R.isNil(property)) {
          Object.keys(property).forEach((key) => {
            this.dataForm[key] = property[key]
          })
        }
      })
    },
    addNewProduct() {
      const cb = (newValue) => {
        this.initProductInfoList()
        this.dataForm.productId=newValue.id
      }
      this.$parent.openProductInfoDialog(cb)
    },
  }
}
</script>
